package com.fas.system.controller;

import com.fas.common.annotation.Log;
import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.domain.entity.SysDept;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.enums.BusinessType;
import com.fas.common.utils.SecurityUtils;
import com.fas.system.domain.FasCooperationCompany;
import com.fas.system.service.IFasCooperationCompanyService;
import com.fas.system.service.IFasCooperationTradeService;
import com.fas.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 合作单位管理表 Controller
 *
 * @date 2022-07-21
 */
@Api(tags = "合作单位管理")
@RestController
@RequestMapping("/system/networking")
public class FasCooperationCompanyController extends BaseController {

    @Resource
    private IFasCooperationCompanyService fasNetworkingCompanyService;
    @Resource
    private ISysDeptService deptService;
    @Resource
    private IFasCooperationTradeService fasCooperationTradeService;

    @ApiOperation(value = "查询合作单位列表")
    @GetMapping("/list")
    public TableDataInfo queryAll(FasCooperationCompany fasNetworkingCompany, Integer pageNum, Integer pageSize){
        Long deptId = SecurityUtils.getDeptId();
        SysDept sysDept = deptService.selectDeptById(deptId);
        String deptType = sysDept.getDeptType();
        if (deptType.equals("1") || deptType.equals("2")){
            if(fasNetworkingCompany.getDeptId() == null){
                fasNetworkingCompany.setDeptId(deptId.intValue());
            }
        }
        startPage();
        return getDataTable(fasNetworkingCompanyService.queryAll(fasNetworkingCompany));
    }

    @ApiOperation(value = "新增合作单位")
    @Log(title = "合作单位", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody FasCooperationCompany fasNetworkingCompany){
        Long deptId = SecurityUtils.getDeptId();
        fasNetworkingCompany.setDeptId(deptId.intValue());
        return fasNetworkingCompanyService.insertFasCooperationCompany(fasNetworkingCompany);
    }

    @ApiOperation(value = "修改合作单位")
    @Log(title = "合作单位", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasCooperationCompany fasNetworkingCompany){
        return fasNetworkingCompanyService.updateFasCooperationCompany(fasNetworkingCompany);
    }

    @ApiOperation(value = "删除合作单位")
    @Log(title = "合作单位", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable("ids") Integer[] ids){
        return fasNetworkingCompanyService.deleteFasCooperationCompany(ids);
    }

    /**
     * 合作单位管理-单位所属行业
     */
    @ApiOperation(value = "合作单位管理-单位所属行业")
    @GetMapping("/dicTrade")
    public TableDataInfo dicTrade(){
        return getDataTable(fasCooperationTradeService.dicTrade());
    }

}
